package com.google.project.server.entity;

import java.io.Serializable;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.project.shared.MessageDTO;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Message implements Serializable {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;
	@Persistent
	private String senderId;
	@Persistent
	private String senderName;
	@Persistent
	private String receiverId;
	@Persistent
	private String receiverName;
	@Persistent
	private String subject;
	@Persistent
	private String content;
	@Persistent
	private int status;
	@Persistent
	private String projectId;
	@Persistent
	private Long createdOnDate;
	@Persistent
	private String parentId;
	@Persistent
	private int typeId;
	@Persistent
	private Project project;

	/***
	 * 
	 * Contructor
	 */

	public Message() {

	}

	public Message(String id, String senderId, String senderName,
			String receiverId, String receiverName,String subject, String content,
			int status, String projectId, Long createdOnDate,String parentId,int typeId) {
		super();
		this.id = id;
		this.senderId = senderId;
		this.senderName = senderName;
		this.receiverId = receiverId;
		this.receiverName = receiverName;
		this.subject=subject;
		this.content = content;
		this.status = status;
		this.projectId = projectId;
		this.createdOnDate = createdOnDate;
		this.parentId=parentId;
		this.typeId=typeId;
	}

	public Message(MessageDTO messageDTO) {
		this.senderId = messageDTO.getSenderId();
		this.senderName = messageDTO.getSenderName();
		this.receiverId = messageDTO.getReceiverId();
		this.receiverName = messageDTO.getReceiverName();
		this.subject=messageDTO.getSubject();
		this.content = messageDTO.getContent();
		this.status = messageDTO.getStatus();
		this.projectId = messageDTO.getProjectId();
		this.createdOnDate = messageDTO.getCreatedOnDate();
		this.parentId=messageDTO.getParentId();
		this.typeId=messageDTO.getTypeId();
	}

	public MessageDTO toDTO() {
		MessageDTO data = new MessageDTO();
		data.setId(id);
		data.setSenderId(senderId);
		data.setSenderName(senderName);
		data.setReceiverId(receiverId);
		data.setReceiverName(receiverName);
		data.setSubject(subject);
		data.setContent(content);
		data.setStatus(status);
		data.setProjectId(projectId);
		data.setCreatedOnDate(createdOnDate);
		data.setParentId(parentId);
		data.setTypeId(typeId);
		return data;
	}
	/*
	 * Update function
	 */
	public void updateFromDTO(MessageDTO messageDTO){
		this.senderId = messageDTO.getSenderId();
		this.senderName = messageDTO.getSenderName();
		this.receiverId = messageDTO.getReceiverId();
		this.receiverName = messageDTO.getReceiverName();
		this.subject=messageDTO.getSubject();
		this.content = messageDTO.getContent();
		this.status = messageDTO.getStatus();
		this.projectId = messageDTO.getProjectId();
		this.createdOnDate = messageDTO.getCreatedOnDate();
		this.parentId=messageDTO.getParentId();
		this.typeId=messageDTO.getTypeId();
	}
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getSenderId() {
		return senderId;
	}

	public void setSenderId(String senderId) {
		this.senderId = senderId;
	}

	public String getSenderName() {
		return senderName;
	}

	public void setSenderName(String senderName) {
		this.senderName = senderName;
	}

	public String getReceiverId() {
		return receiverId;
	}

	public void setReceiverId(String receiverId) {
		this.receiverId = receiverId;
	}

	public String getReceiverName() {
		return receiverName;
	}

	public void setReceiverName(String receiverName) {
		this.receiverName = receiverName;
	}
	
	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	public Long getCreatedOnDate() {
		return createdOnDate;
	}

	public void setCreatedOnDate(Long createdOnDate) {
		this.createdOnDate = createdOnDate;
	}
	
	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public int getTypeId() {
		return typeId;
	}

	public void setTypeId(int typeId) {
		this.typeId = typeId;
	}
	
}
